<template>
    <div class="achievementYearDetail">
        <el-breadcrumb separator="/" class="bread-title">
            <el-breadcrumb-item :to="{ path: '/achievementYear'}">业绩激励-年</el-breadcrumb-item>
            <el-breadcrumb-item>员工分配表</el-breadcrumb-item>
        </el-breadcrumb>

       <el-form :inline="true" :model="ruleForm" class="demo-form-inline">
           <el-form-item label="员工姓名：">
               <el-input placeholder="请输入员工姓名" v-model.trim="ruleForm.staffName" maxlength="20"></el-input>
           </el-form-item>
           <el-form-item>
               <el-button type="primary"  @click="searchList" id="monitorEnter">查询</el-button>
               <el-button type="primary"  @click="exportReport">导出</el-button>
               <el-button type="primary"  @click="adjustReport">调整报表</el-button>
           </el-form-item>
       </el-form>
        <h3>{{this.ruleForm.year}}年好生活员工分配表</h3>
        <el-table :data="tableData" class="mt20" border style="width: 100%">
            <el-table-column prop="date" label="序号" width="80" align="center" :formatter="inittotal"></el-table-column>
            <el-table-column prop="staffCode" label="工号" align="center">
                <template  slot-scope="scope">
                    <p v-if="scope.$index !==0" > {{scope.row.staffCode}}</p>
                    <p v-else>——</p>
                </template>
            </el-table-column>
            <el-table-column prop="staffName" label="姓名" align="center">
                <template  slot-scope="scope">
                    <p v-if="scope.$index !==0" > {{scope.row.staffName}}</p>
                    <p v-else>——</p>
                </template>
            </el-table-column>
            <el-table-column prop="departmentName" label="部门" align="center">
                <template  slot-scope="scope">
                    <p v-if="scope.$index !==0" >{{scope.row.departmentName}}</p>
                    <p v-else>——</p>
                </template>
            </el-table-column>
            <el-table-column prop="stationName" label="岗位名称" align="center">
                <template  slot-scope="scope">
                    <p v-if="scope.$index !==0" >{{scope.row.stationName}}</p>
                    <p v-else>——</p>
                </template>
            </el-table-column>
            <el-table-column prop="stationStartTime" label="入职时间" align="center">
                <template  slot-scope="scope">
                    <p v-if="scope.$index !==0">{{filterstimer(scope.row.stationStartTime)}}</p>
                    <p v-else>——</p>
                </template>
            </el-table-column>
            <el-table-column prop="stationEndTime" label="离职时间" align="center">
                <template  slot-scope="scope">
                    <p v-if="scope.$index !==0" >{{filterstimer(scope.row.stationStartTime)}}</p>
                    <p v-else>——</p>
                </template>
            </el-table-column>
            <el-table-column prop="stationEffectDays" label="在岗天数" align="center">
                <template  slot-scope="scope">
                    <p v-if="scope.$index !==0" >{{scope.row.stationEffectDays}}</p>
                    <p v-else>——</p>
                </template>
            </el-table-column>
            <el-table-column prop="actualAmount" label="实际金额(元)" :formatter="initCash" align="center">
            </el-table-column>
            <el-table-column prop="adjustAmount" label="调整金额(元)" :formatter="initCash" align="center">
            </el-table-column>
            <el-table-column prop="realAmount" label="实发金额(元)" :formatter="initCash" align="center">
            </el-table-column>
        </el-table>
        <div class="pagebar">
          <el-pagination
            background
            layout="total, sizes, prev, pager, next"
            :current-page.sync="ruleForm.pageNum"
            :page-sizes="[10, 20, 30, 40]"
            :page-size="ruleForm.pageSize"
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :total="totalSize">
          </el-pagination>
        </div>
    </div>
</template>

<script type="text/ecmascript-6">
    import api from '@/api/apiPath'
    export default {
        name: 'achievementYearDetail',
        data() {
            return {
                tableData: [],
                ruleForm:{
                    staffName:undefined,
                    pageNum: 0,
                    pageSize: 10,
                    allotYearId:undefined,
                    year:undefined,
                },
                totalSize:0,
            }
        },
        created() {
            this.ruleForm.allotYearId = this.$route.query.allotYearId
            this.ruleForm.year = this.$route.query.year
            this.getlist()
        },
        methods: {
            filterstimer(val){
                if (val) {
                   return val.substring(0,11)
                }
            },
            inittotal(row, column, cellValue, index){
                if(index == 0){
                    return '合计';
                }
                return index
            },
            initCash(row, column, cellValue, index){
                if (!cellValue && cellValue !== 0) {
                    return 
                }
                if(cellValue !== 0){
                    return cellValue.toFixed(2).toString().replace(/\B(?=(\d{3})+(?!\d))/g,",");
                }
                if(cellValue == 0){
                    return "0.00"
                }
            },
            //导出报表
            exportReport(){
                // REVENUEALORTGENERATEREPORT
                this.axios.post(api.COMMALLOCATIONYEAR, {allotYearId :this.ruleForm.allotYearId}).then((res) => {
                   if (res.data.code == 200) {
                        this.$alert('已导出，请前往报表查询下载', {
                            confirmButtonText: '确定',
                          });
                   }
                })
            },
            adjustReport(){
                this.$router.push({path:'/achievementYearDetailChange',query:{allotYearId:this.ruleForm.allotYearId,year:this.ruleForm.year}})
            },
            searchList(){
                this.ruleForm.pageNum = 1
                this.getlist()
            },
            handleCurrentChange(){
                this.getlist()
            },
            handleSizeChange(val){
                this.ruleForm.pageSize = val
                this.getlist();
            },
            getlist(){
                this.axios.post(api.GETREYEARDETAILIST, this.ruleForm).then((res) => {
                    if (res.data.code == 200) {
                        this.tableData = res.data.data.data;
                        this.tableData.unshift(res.data.data.totalData)
                        this.totalSize = res.data.data.total;
                    }
                })
            },
        }
    }
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style lang="stylus">

</style>
